package day01_iterator;

/**
 * @author Koizumi Sinya
 * @date 2018/11/06. 21:38
 * @edithor
 * @date
 */
public class BookStoreIterator implements Iterator {
    private BookStore bookStore;
    private int index;

    public BookStoreIterator(BookStore bookStore) {
        this.bookStore = bookStore;
        this.index = 0;
    }

    @Override
    public boolean hasNext() {
        if (index < bookStore.getLength()) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public Object next() {
        Book book = bookStore.getBookAt(index);
        index++;
        return book;
    }
}
